<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>栏目管理</title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="format-detection" content="telephone=no"/>
    <link rel="stylesheet" href="static/css/x-admin.css" media="all"/>
    <style type="text/css">
        .open {
            border: 1px solid #ccc;
            padding: 0 3px 0 3px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="x-nav">
    <span class="layui-breadcrumb"> <a><cite>首页</cite></a> <a><cite>栏目管理</cite></a> <a><cite>栏目列表</cite></a> </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                          style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <xblock>
        <form action="/catelist" method="post">
            <div class="layui-col-md7">
                <div class="layui-inline">
                    <input type="text" name="keyword" id="keyword" placeholder="请输入名字" class="layui-input">
                </div>
                <button class="layui-btn" type="submit"><i class="layui-icon">&#xe615;</i>搜索</button>
            </div>
        </form>
        <button class="layui-btn" onclick="addBut()"><i
                class="layui-icon"></i>添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<span class="layui-badge">{{ count }}</span> 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr pid="0">

            <th><input type="checkbox" name="" value=""/></th>
            <th> ID</th>

        </tr>
        </thead>
        <tbody id="x-img">
        {% for row in data %}
            <tr id="{{ row[0] }}" pid="0">
                <td><input type="checkbox" value="{{ row[0] }}" name=""/></td>

                <td class="td-manage">
                    {#                    <a style="text-decoration:none" onclick="cate_stop(this, '{{ row[0] }}', '0')" href="javascript:;"#}
                    {#                       title="显示"> <i class="layui-icon"></i> </a>#}
                    <a title="编辑" href="javascript:;" onclick="updateBut({{ row[0] }})"
                       class="ml-5"
                       style="text-decoration:none"> <i class="layui-icon"></i> </a>

                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
    <div id="page123"></div>
</div>
{#<script src="static/lib/layui/layui.js" charset="utf-8"></script>#}
{#<script src="static/js/x-layui.js" charset="utf-8"></script#}
<script src="static/js/jquery.min.js" charset="utf-8"></script>
<!-- 引入 layui.js -->
<script src="static/lib/layui/layuis.js"></script>
<script>
    layui.use('laypage', function () {
        var laypage = layui.laypage;
        //执行一个laypage实例
        laypage.render({
            elem: 'page123',
            count: {{ count }}, //数据总数，从后端得到
            curr: {{ page }}, //当前页数，从后端得到
            jump: function (obj, first) {
                if (!first) {
                    // 发送分页的请求，加载对应页码的数据
                    window.location.href = '/catelist?page=' + obj.curr;
                }
            }
        });
    });

</script>
<script>

    /*添加*/
    var updateFrame = null;

    function addBut() {
        console.log('123123123')
        layui.use('layer', function () {
            var layer = layui.layer;
            //iframe层-父子操作
            updateFrame = layer.open({
                title: "新增信息",
                type: 2,
                area: ['70%', '60%'],
                scrollbar: false,	//默认：true,默认允许浏览器滚动，如果设定scrollbar: false，则屏蔽
                maxmin: true,
                content: '/cate_add'
            });
        });

    }


    // 修改
    var updateFrame = null;

    function updateBut(id) {
        console.log(id)
        layui.use('layer', function () {
            var layer = layui.layer;

            //iframe层-父子操作
            updateFrame = layer.open({
                title: "信息修改",
                type: 2,
                area: ['70%', '60%'],
                scrollbar: false,	//默认：true,默认允许浏览器滚动，如果设定scrollbar: false，则屏蔽
                maxmin: true,
                content: '/cate_update?id=' + id
            });
        });

    }

    /*删除*/
    function cate_del(obj, id) {
        layer.confirm('确认要删除吗？', {icon: 3, title: '提示信息'}, function (index) {
            $.ajax({
                type: "post",
                url: "/cate_del",
                data: {id: id},
                dataType: "json",
                success: function (data) {

                    if (data.status == 1) {
                        //发异步删除数据
                        $(obj).parents("tr").remove();
                        layer.msg(data.info, {icon: 6, time: 1000});
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                        return false;
                    } else {
                        layer.msg(data.info, {icon: 5, time: 1000});
                        return false;
                    }
                }
            });

        });
    }


</script>
</body>
</html>